package com.health.viewscontrols.tjbg.fragment;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.blankj.utilcode.util.GsonUtils;
import com.health.R;
import com.health.httpbean.model.FmModel;
import com.health.tablebean.SBCL_DATA;
import com.health.viewscontrols.NovaApplication;
import com.health.viewscontrols.medical.bean.PefBean;
import com.health.viewscontrols.tjbg.base.BaseFragment;

import java.util.List;

/**
 * author : xiaoxin
 * date   : 2020/12/21 11:52
 * desc   : 肺功能报告
 * update :
 */
public class PEFReportFragment extends BaseFragment  {


    private LinearLayout ll_root;
    private TextView tv_fvc, tv_fev05,tv_fev1,tv_fev1_fvc,tv_pef,tv_pef25,tv_pef50,tv_pef75,
            tv_pef2575, tv_fev3,tv_fev6,tv_peft,tv_evol;

    private TextView tv_tjbg_no_data;
    String strWhere = "IDCARD = '" + NovaApplication.getUserInfo().getIDCARD() + "'";

    public static PEFReportFragment newInstance() {

        PEFReportFragment fragment = new PEFReportFragment();
        Bundle args = new Bundle();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.fragment_report_pef;
    }

    @Override
    protected void initView(View view) {
        ll_root = view.findViewById(R.id.ll_root);
        tv_fvc = view.findViewById(R.id.tv_fvc);
        tv_fev05 = view.findViewById(R.id.tv_fev05);
        tv_fev1 = view.findViewById(R.id.tv_fev1);
        tv_fev1_fvc = view.findViewById(R.id.tv_fev1_fvc);
        tv_pef = view.findViewById(R.id.tv_pef);
        tv_pef25 = view.findViewById(R.id.tv_pef25);
        tv_pef50 = view.findViewById(R.id.tv_pef50);
        tv_pef75 = view.findViewById(R.id.tv_pef75);
        tv_pef2575 = view.findViewById(R.id.tv_pef2575);
        tv_fev3 = view.findViewById(R.id.tv_fev3);
        tv_fev6 = view.findViewById(R.id.tv_fev6);
        tv_peft = view.findViewById(R.id.tv_peft);
        tv_evol = view.findViewById(R.id.tv_evol);

        tv_tjbg_no_data = view.findViewById(R.id.tv_tjbg_no_data);
    }

    @Override
    protected void initData() {
        try {
            List<SBCL_DATA> list1 = NovaApplication.fdbmanger.findAllByWhere(SBCL_DATA.class,
                    strWhere + " AND CL_TYPE = '肺功能' ORDER BY CL_TIME DESC");

            if (list1 == null || list1.size() <= 0) {
                ll_root.setVisibility(View.GONE);
                tv_tjbg_no_data.setVisibility(View.VISIBLE);
                tv_tjbg_no_data.setText("暂无肺功能体检数据");
            } else {
                ll_root.setVisibility(View.VISIBLE);
                tv_tjbg_no_data.setVisibility(View.GONE);
                SBCL_DATA sbclData = list1.get(0);
                PefBean pefBean = GsonUtils.fromJson(sbclData.getCL_VALUE(), PefBean.class);

                setText(tv_fvc, pefBean.getFvc());
                setText(tv_fev05, pefBean.getFev05());
                setText(tv_fev1, pefBean.getFev1());
                setText(tv_fev1_fvc, pefBean.getFev1_fvc());
                setText(tv_pef, pefBean.getPef());
                setText(tv_pef25, pefBean.getPef25());
                setText(tv_pef50, pefBean.getPef50());
                setText(tv_pef75, pefBean.getPef75());
                setText(tv_pef2575, pefBean.getPef2575());
                setText(tv_fev3, pefBean.getFev3());
                setText(tv_fev6, pefBean.getFev6());
                setText(tv_peft, pefBean.getPeft());
                setText(tv_evol, pefBean.getEvol());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void setText(TextView textView, String value) {
        if (!TextUtils.isEmpty(value)) {
            textView.setText(value);
        } else {
            textView.setText("");
        }
    }

}
